<template>
  <div class="comment">
    <div>
      <textarea class="comment-textarea" ctype="textarea" placeholder="想对他说点什么" v-model="comment" />
      <div class="addBtn">
        <div style="margin:0px 20px">
          <V3Emoji @click-emoji="appendText" />
        </div>
        <button @click="addComment">
          发送
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import V3Emoji from 'vue3-emoji'
import 'vue3-emoji/dist/style.css'
import { ElMessage } from 'element-plus'
import { onMounted, reactive, toRefs } from '@vue/runtime-core'
import { useRoute } from 'vue-router'
export default {
  name: 'comment',
  props: {
    mainIp: {
      default: ''
    }
  },
  components: { V3Emoji },
  setup (props, context) {
    const route = useRoute()
    const data = reactive({
      cip: '获取不到ip',
      comment: '',
    })
    onMounted(() => {
      data.cip = returnCitySN['cip']
    })
    function addComment () {
      if (!data.comment.trim()) {
        ElMessage({
          showClose: true,
          message: '不能为空',
          type: 'error',
        })
        return
      }
      context.emit('commentReply', { cip: data.cip, comment: data.comment, mainIp: props.mainIp, articleId: route.query.id })
    }
    // 添加表情包
    function appendText (meme) {
      data.comment += meme
    }
    return {
      ...toRefs(data),
      addComment,
      appendText
    }
  }
}
</script>
<style lang="scss" scoped>
.comment {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0px;
  background: #fff;
  transition: all 1s;
  overflow: hidden;
}
.addBtn {
  display: flex;
  justify-content: flex-end;
  margin: 10px;
}
.comment-textarea {
  font-size: 0.875rem;
  color: #555 !important;
  outline: none;
  border: 1px solid rgba(144, 147, 153, 0.31);
  border-radius: 4px;
  padding: 10px 10px;
  min-height: 122px;
  resize: none;
  width: 90%;
  font-size: 14px;
  border-radius: 4px;
  background: url("@/assets/image/input.gif") right no-repeat;
  background-size: auto 100%;
  font-weight: 20px;
}
button {
  width: 9em;
  height: 3em;
  border-radius: 30em;
  font-size: 12px;
  font-family: inherit;
  border: none;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

button::before {
  content: "";
  width: 0;
  height: 3em;
  border-radius: 30em;
  position: absolute;
  top: 0;
  left: 0;
  background-image: linear-gradient(to right, #0fd850 0%, #f9f047 100%);
  transition: 0.1s ease;
  display: block;
  z-index: -1;
}

button:active::before {
  width: 9em;
}
</style>